package com.jwthhealth_pub.wristband.steps.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.base.BaseActivity;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.wristband.steps.fragment.FragmentDay;
import com.jwthhealth_pub.wristband.steps.fragment.FragmentMooth;
import com.jwthhealth_pub.wristband.steps.fragment.FragmentWeek;
import com.jwthhealth_pub.wristband.steps.fragment.FragmentYear;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.jwthhealth_pub.common.LogUtil.makeLogTag;

/**
 * 步数统计
 * Created by yang on 2017/12/16.
 */

public class StepsStatisticsActivity extends BaseActivity {

    private final String TAG = makeLogTag(StepsStatisticsActivity.class);

    @BindView(R.id.title_layout)
    TitleLayout titleLayout;

    @BindView(R.id.rb_day)
    RadioButton rb_day;
    @BindView(R.id.rb_week)
    RadioButton rb_week;
    @BindView(R.id.rb_month)
    RadioButton rb_month;
    @BindView(R.id.rb_year)
    RadioButton rb_year;

    @BindView(R.id.vpNewsList)
    FrameLayout vpNewsList;
    @BindView(R.id.rgChannel)
    RadioGroup rgChannel;
    int currIndex = -1;
    private List<Fragment> fragmentList=new ArrayList<Fragment>();

    FragmentManager fragmentManager;
     FragmentTransaction fragmentTransaction;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stepstatis);
        ButterKnife.bind(this);
        initView();
    }

    @Override
    protected void title() {
        titleLayout.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    private void initView() {
        fragmentList.add(new FragmentDay());
        fragmentList.add(new FragmentWeek());
        fragmentList.add(new FragmentMooth());
        fragmentList.add(new FragmentYear());

         fragmentManager = getSupportFragmentManager();
         fragmentTransaction =fragmentManager.beginTransaction();
         fragmentTransaction.add(R.id.vpNewsList,new FragmentDay());
         fragmentTransaction.commit();  //提交修改
//        viewPager.setOnPageChangeListener(this);
//
//        adapter=new StepsPageFragmentAdapter(super.getSupportFragmentManager(),fragmentList);
//        viewPager.setAdapter(adapter);
//        viewPager.setCurrentItem(0);
        rgChannel.setOnCheckedChangeListener(
                new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup group,
                                                 int checkedId) {
                        switch (checkedId) {
                            case R.id.rb_day:
                                rb_day.setChecked(true);
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentDay());
                                fragmentTransaction.commit();  //提交修改
                                break;
                            case R.id.rb_week:
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentWeek());
                                fragmentTransaction.commit();  //提交修改
                                rb_week.setChecked(true);
                                break;
                            case R.id.rb_month:
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentMooth());
                                fragmentTransaction.commit();  //提交修改
                                rb_month.setChecked(true);
                                break;
                            case R.id.rb_year:
                                fragmentTransaction =fragmentManager.beginTransaction();
                                fragmentTransaction.replace(R.id.vpNewsList,new FragmentYear());
                                fragmentTransaction.commit();  //提交修改
                                rb_year.setChecked(true);
                                break;
                            default:
                                break;
                        }
                    }
                });
    }


}
